Skip to content

Fix perception engine loop#20

Open
trisha-ant wants to merge 1 commit intopskeshu:mainfrom
trisha-ant:fix-perception-engine-loop
Open

Fix perception engine loop#20
trisha-ant wants to merge 1 commit intopskeshu:mainfrom
trisha-ant:fix-perception-engine-loop

Conversation

@trisha-ant
Copy link
Copy Markdown

@trisha-ant trisha-ant commented Apr 7, 2026

Summary

Four changes:

  • Crash fix: _run_reasoning_loop() returned 2-tuples but perceive() unpacked 3 — every call raised, got swallowed, and degraded to stage="early".
  • Crash fix: _check_interval_rules() passed an unsupported timepoint= kwarg to IntervalRule.matches()TypeError was swallowed, so interval rules never fired.
  • Type cleanup: declare initial_stage / initial_confidence on PerceptionResult so the multishot block's assignments are real fields.
  • Contract change: _run_reasoning_loop() now returns a complete conversation history — the model's final assistant turn (and on the verification path, its tool_result) is appended to messages before returning. This is behaviorally inert today (multishot_turns=0 means nothing consumes messages), but it changes what context any future continuation sees: the model will now have its own prior answer in history when asked to reconsider, rather than a conversation that skips straight from the last user turn to the reconsider prompt.

Changes

1. _run_reasoning_loop() returns (result, trace, messages) at all exits + NotImplementedError stubsengine.py
perceive() unpacks 3 values from _run_reasoning_loop() (line 456), but the function returned 2-tuples at every exit. The ValueError was caught by PerceptionManager.process_image and converted to stage="early", confidence=0.0, so every prediction silently degraded. All three returns now include messages. The undefined _build_reconsider_prompt / _call_claude referenced in the multishot block are stubbed to raise NotImplementedError pointing at multishot_turns=0.

2. Drop timepoint= kwarg from IntervalRule.matches() calltimelapse.py
_check_interval_rules() passed timepoint=estate.timepoints_acquired, but IntervalRule.matches() has no such parameter. The TypeError was swallowed by the broad except wrapping perception, so configured interval rules never applied. Dropped the kwarg at the call site for now — if we want timepoint-based triggering later, IntervalRule.matches() (timelapse_models.py:42) needs a timepoint: int | None = None parameter added alongside.

3. Add initial_stage / initial_confidence to PerceptionResultsession.py
The multishot block assigns these (engine.py:466, 495-496) but they weren't declared on the dataclass. Now real Optional fields; pyright is clean and the values survive dataclasses.asdict().

4. Append the assistant turn to messages before early returnsengine.py
The end-turn and verification return paths parsed the model's final answer but never appended it to messages, so any caller continuing the conversation would send a user turn directly after a user turn with the model's own answer missing. Both paths now append the assistant turn; the verification path also appends a tool_result so the history is API-valid. No effect on the default path today since messages is only consumed when multishot_turns > 0, but it changes the contract of what the function returns.

Testing

  • pytest tests/ — 489 passed, 3 skipped, 0 regressions (14 pre-existing async-test failures from pytest-asyncio not being installed reproduce identically on clean HEAD)
  • pyright session.py — 0 errors
  • pyright engine.py lines 460-509 (multishot block) — 0 errors; remaining engine.py errors are pre-existing and unrelated
  • Adversarial: re-adding timepoint= raises TypeError; invoking either stub raises NotImplementedError

_run_reasoning_loop returned 2-tuples but perceive() unpacked 3, and
_check_interval_rules passed an unsupported timepoint= kwarg to
IntervalRule.matches(). Both errors were swallowed by broad except
handlers, silently degrading every prediction to "early" and preventing
interval rules from ever firing. Also adds initial_stage/initial_confidence
to PerceptionResult and completes the messages history at early returns so
the multishot scaffold is type-clean and continuable.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant